package com.lee.boot.head.first.demo.annotation.annotationImpl;



import com.lee.boot.head.first.demo.annotation.SexValidate;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author edz
 * @Auther: Lee
 * @Date: 2018/6/28 12:32
 * @Description:
 */
public class SexValidateClass implements ConstraintValidator<SexValidate, Object> {
    private String values;



    @Override
    public void initialize(SexValidate sexValidate) {
        this.values = sexValidate.value();
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        String[] split = values.split(",");
        boolean flag =false;
        for (String s : split) {
            if (s.equals(o)){
                flag = true;
                break;
            }
        }
        return flag;
    }
}
